<?php 
require('./roots.php');
require_once('./classes/rbac.php');
$lang=$_POST['lang'];
if(isset($lang)){

$_SESSION['lang']=$lang;

}

//$_SESSION['sess_login_username']='root';
//$_SESSION['roles']=array('rol'=>'1');

$login=$_POST['login'];
$pass=$_POST['password'];
$role1=$_POST['role0'];
if ($login!='' && $pass!=''){
    $rbac= new rbac();
    $user=$rbac->Obtener_usuario($login);
    //var_dump($user);
    if($user){
        require_once("./AES.class.php");
        require_once("/var/RBAC_CONFIG.php");
        $aes=new AES($cypherPass);
        $oldPass=$user["password"];
        //var_dump("cypher: ".$cypherPass);
        //var_dump("password desde db: ".$oldPass);
        $oldPass=base64_decode($oldPass);
        $aespassword=$aes->decrypt($oldPass);
        //var_dump("password decriptado: ".$aespassword);
        //var_dump($oldPass);
        if($aespassword==md5($pass)){
            $_SESSION['sess_login_username']=$login;
            $gui=$rbac->Obtener_roles($user['id']);
            //var_dump($gui);
        }
        else
        header('Location: index.php?valid=F');
    }
    else
    header('Location: index.php?valid=F');

}
else
    header('Location: index.php?valid=F');




include('languaje/'.$_SESSION['lang'].'/lang_'.$_SESSION['lang'].'_rbac.php');

include "header.php";


$action='rbac.php';

$msj = '';


?>
 <form method="post" action="<?php echo $action;?>" name="regform" ENCTYPE="multipart/form-data"> 


	<div id="page">
	<div id="page-bgtop">
	<div id="page-bgbtm">
		<div id="content">
			<div class="post">
			<div class="post-bgtop">
			<div class="post-bgbtm">
				<h2 class="title"><a href="#"><?php echo $LDAGL; ?></a></h2>
				 <?php 
                                

                                    $i=0;
                                    if ($gui)
                                 foreach($gui as $array=>$name){

                                     ?>

                                                                    <div class="table">
                                                                            <table width=100%>
                                                                                    <tr>
                                                                                            <td width=40%>
                                                                                                    <?php echo $name['id_role']; ?>
                                                                                            </td>
                                                                                            <td width=30%>
                                                                                                    <?php
                                                                                                    echo ('<input type="checkbox" name="role'.$i.'" value="'.$name['id_role'].'">');
                                                                                                    ?>
                                                                                            </td>
                                                                                    </tr>
                                                                            </table>
                                                                    </div>
                                                                      <?php $i++;}
                                                                        echo ('<input type="submit" value="'.$LDAsignar.'" name="validar" class="botonDesign" />');

                                                                  ?>
				<div class="entry">
					<p>
																																				
						
								<?php echo $LDRolesMensaje; ?>
					</p>
				</div>
			</div>
			</div>
			</div>
			
		<div style="clear: both;">&nbsp;</div>
		</div>

		<div id="sidebar">
				<ul>
					<li>
						<h2><?php echo $LDCategorias; ?></h2>

						<?php

						include "MenuRbac.php";

						?>	
						<script type="text/javascript">

						cssdropdown.startchrome("chromemenu")

						</script>
				</li>
			</ul>
		</div>

		<div style="clear: both;">&nbsp;</div>
	</div>
	</div>
	</div>
</div>

</form>

<?php

include "footer.php";

?>
